package com.vhuomai.system.service.impl;

import com.quanyue.auto.util.GlobalContext;
import com.vhuomai.system.entity.BaseSysShare;
import com.vhuomai.system.mapper.ShareMapper;
import com.vhuomai.system.service.ShareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author harris
 */
@Service
public class ShareServiceImpl implements ShareService {
    
    @Autowired
    private ShareMapper shareMapper;
    
    @Override
    public List<BaseSysShare> findAll() {
        return shareMapper.findByMerchant(GlobalContext.merchantNo());
    }
    
    @Override
    public BaseSysShare findByPage(String pageKey) {
        return shareMapper.findByPageKey(GlobalContext.merchantNo(), pageKey);
    }
    
    @Override
    public BaseSysShare add(BaseSysShare share) {
        share.setMerchantNo(GlobalContext.merchantNo());
        share.setCreateTime(LocalDateTime.now());
        share.setUpdateTime(share.getCreateTime());
        shareMapper.insert(share);
        return share;
    }
    
    @Override
    public void update(BaseSysShare share) {
        share.setUpdateTime(LocalDateTime.now());
        shareMapper.updateSelective(share);
    }
    
    @Override
    public void remove(int shareId) {
        shareMapper.deleteOne(shareId);
    }
}
